import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public final class Input implements MouseListener, KeyListener
{
	//constructor
	public static boolean[] keyarray = new boolean[200];
	public Input()
	{
		System.out.println("Input system booting up...");
		if (game.goodpc == true){
		Main.gui.addKeyListener(this);
		Main.gui.addMouseListener(this);
		Main.gui.setFocusTraversalKeysEnabled(false);
		}else{
			legacyengine.canvas.addKeyListener(this);
			legacyengine.canvas.addMouseListener(this);
			legacyengine.canvas.setFocusTraversalKeysEnabled(false);
		}
	}
	// right 39, left 37, up 38, down 40, space 32, W = 87, A = 65, S = 83, D = 68, # F = 70, G= 71, H = 72 `=192
	public void mouseClicked(MouseEvent e) {
		//e.consume();
	}
	public void mouseEntered(MouseEvent e) {}
	public void mouseExited(MouseEvent e) {}
	public void mousePressed(MouseEvent e) {
		//e.consume();
		System.out.println("Mouse Pressed @ "+e.getPoint().x+","+e.getPoint().y);
		if (RenderEngine.paused)
		{
			
		}else{
		game.Mouse(e.getPoint().x,e.getPoint().y);
		}
	}
	public void mouseReleased(MouseEvent e) {
		e.consume();
	}
	public void keyTyped(KeyEvent e)
	{
	    	e.consume();
	}
	public void keyPressed(KeyEvent e)
	{
		e.consume();
	    	//System.out.println("Key Typed - "+e.getKeyChar()+" - "+e.getKeyCode());
	    	//first, see if the pressed key is a command, if not, pass it to game.java
		command(e.getKeyCode());
		keyarray[e.getKeyCode()] = true;
	    		
	}
	public void keyReleased(KeyEvent e)
	{
		keyarray[e.getKeyCode()] = false;
	    	e.consume();
	}
	//command Processor.
	public static void command(int cmnd)
	{
			if (cmnd == 19 || cmnd == 27){
				System.out.println("running command "+cmnd);	
				if (game.goodpc == true){
					if (RenderEngine.paused == true){
						//SoundEffect.play("start2.wav");
						RenderEngine.paused = false;
					}else{
						RenderEngine.paused = true;
					}
				}else{
					if (legacyengine.paused == true){
						//SoundEffect.play("start2.wav");
						legacyengine.paused = false;
					}else{
						legacyengine.paused = true;
					}
				}
			}
			if (cmnd == 192){
			Main.timekeeperdisplay();
			}
	}
}
